package com.chookss.home.gallery.adapter;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chookss.R;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.home.entity.GalleryHotSearchEntity;
import com.chookss.home.gallery.GalleryListActivity;
import com.chookss.tools.GlideUtils;
import com.chookss.tools.Utils;
import com.chookss.view.MyRoundLayout;
import com.johnrambo.ktea.common.klogutil.KLog;

import java.util.List;

import io.reactivex.annotations.Nullable;

public class GallerySearchHotAddressAdapter extends BaseQuickAdapter<GalleryHotSearchEntity.CityListBean, BaseViewHolderEx> {
    private Activity context;
    private int width, height;
    private int type = 1;//

    public GallerySearchHotAddressAdapter(int layoutResId, Activity context, @Nullable List<GalleryHotSearchEntity.CityListBean> data, int type) {
        super(layoutResId, data);
        this.context = context;
        this.type = type;
        width = (Utils.getScreenWidthPixel(context) - Utils.dip2px(context, 48)) / 3;
    }

    @Override
    protected void convert(BaseViewHolderEx helper, GalleryHotSearchEntity.CityListBean item) {
        MyRoundLayout rlBg = helper.getView(R.id.rlBg);
        ImageView ivBg = helper.getView(R.id.ivBg);
        TextView tvTagTitle = helper.getView(R.id.tvTagTitle);
        ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) rlBg.getLayoutParams();
        params.height = width;
        params.width = width;
        rlBg.setLayoutParams(params);
        KLog.i(item.getName()+"====");
        GlideUtils.loadCustomRound(context,item.getImagePath(),ivBg,15);
        if(Utils.isNull(item.getName())){
            tvTagTitle.setText("未知");
        }else{
            if(item.getName().equals("a")){
                tvTagTitle.setText("未知");
            }else{
                tvTagTitle.setText(item.getName());
            }
        }
        helper.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, GalleryListActivity.class);
                intent.putExtra("data", tvTagTitle.getText().toString());
                intent.putExtra("city",item.getName());
                intent.putExtra("tagCode","");
                intent.putExtra("catalogCodes","");
                intent.putExtra("createTime","");
                intent.putExtra("searchType", 3+"");
                intent.putExtra("roleType", 1);
                context.startActivity(intent);
            }
        });
    }
}
